<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        ul {
            list-style-type: none;
        }
        
        .box {
            width: 400px;
            height: 300px;
            border: 1px solid #ccc;
            margin: 100px auto;
            overflow: hidden;
        }
        
        .hd {
            height: 45px;
        }
        
        .hd span {
            display: inline-block;
            width: 90px;
            background-color: pink;
            line-height: 45px;
            text-align: center;
            cursor: pointer;
        }
        
        .hd span.current {
            background-color: lightblue;
        }
        
        .bd li {
            height: 255px;
            background-color: lightblue;
            display: none;
        }
        
        .bd li.current {
            display: block;
        }
    </style>

</head>

<body>
    <div class="box" id="box">
        <div class="hd">
            <span class="current">体育</span>
            <span>娱乐</span>
            <span>新闻</span>
            <span>综合</span>
        </div>
        <div class="bd">
            <ul>
                <li class="current">我是体育模块</li>
                <li>我是娱乐模块</li>
                <li>我是新闻模块</li>
                <li>我是综合模块</li>
            </ul>
        </div>
    </div>
    <script>
        var box = document.getElementById("box");
        //获取所有的span
        var spans = box.getElementsByTagName("span");


        //1 给head注册事件
        for (var i = 0; i < spans.length; i++) {
            var span = spans[i];
            span.onclick = fn;
        }

        function fn() {
            //2 点击head 把其他head中的span的current移除，把当前点击的span的类样式设置为current
            //移除所有span的类样式
            for(var i = 0; i < spans.length; i++) {
                var span = spans[i];
                //设置自定义属性
                span.setAttribute("index",i);
                //移除类样式
                span.removeAttribute("class");
            }
            //让当前的span的类样式为current
            this.setAttribute("class","current");

            //3 设置当前对应的li显示，其他li隐藏
            //获取所有的li
            var list = box.getElementsByTagName("li");
            for(var i=0; i< list.length; i++) {
                //移除所有li的class属性
                var li = list[i];
                li.removeAttribute("class");
            }
            //让和点击的span对应的li显示
            //如何获取当前点击的span的索引
            var index = parseInt( this.getAttribute("index")) ; //通过自定义属性获取到的值，都是string
            //获取对应的li
            list[index].setAttribute("class","current");

        }


    </script>
</body>

</html>